package LeetCode.month01.day12;

import java.util.Arrays;

public class No75 {
    public static void main(String[] args) {
        int[] arr = new int[]{1,0,2,0,1,1,0,2,2,0,0,1,1};
        sortColors(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sortColors(int[] nums) {
        int left = 0,right = nums.length-1;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]==0){
                int temp = nums[i];
                nums[i] = nums[left];
                nums[left] = temp;
                left++;
            }
            if(nums[i]==2){
                int temp = nums[i];
                nums[i] = nums[right];
                nums[right] = temp;
                right--;
                i--;
            }
            if(i==right) {
                break;
            }
        }
    }
}
